package com.cxc.java8;

import java.util.Optional;

public class OptionalInAction {

    public static void main(String[] args) {

        Optional.ofNullable(getInsuranceNameByOptional(null)).ifPresent(System.out::println);

    }

    private static String getInsuranceNameByOptional(Person p){

        return Optional.ofNullable(p).flatMap(Person::getCar).flatMap(Car::getInsurance).map(
                Insurance::getName).orElse("Unknonw");

    }






}
